import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { TMagicTowerConfig } from "../../../Message/Db/Tables/TMagicTowerConfig";
import { StringHelper } from "../../../com/gengine/utils/StringHelper";
import { Cache } from "../cache/Cache";
import { DataProvider } from "../../../fl/data/DataProvider";
import { JumpFloorItemInfo } from "../view/copy/magicTower/com/JumpFloorItemInfo";
type int = number;
//class MagicTowerConfig
    
    export  class MagicTowerConfig
    {
        constructor()
        {
            
            this._FloorInfoDic = new Map<any, any> /* flash.utils.Dictionary */();
            this._maxFloorDic = new Map<any, any> /* flash.utils.Dictionary */();
            if (MagicTowerConfig._instance != null) 
            {
                throw new Error(" MagicTowerConfig 单例 ");
            }
            this.init();
            return;
        }

        public init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_magic_tower_config.json");
            this.write(loc1);
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc1 of loc4) 
            {
                loc2 = new TMagicTowerConfig();
                loc2.addBossId = loc1.addBossId;
                loc2.bossNum = loc1.bossNum;
                loc2.copyCode = loc1.copyCode;
                loc2.delBossId = loc1.delBossId;
                loc2.floor = loc1.floor;
                loc2.realFloor = loc1.realFloor;
                loc2.haveBoss = loc1.haveBoss;
                loc2.intoX = loc1.intoX;
                loc2.intoY = loc1.intoY;
                loc2.killBossId = StringHelper.getString(loc1.killBossId);
                loc2.limitTime = loc1.limitTime;
                loc2.mapId = loc1.mapId;
                loc2.rewardExp = loc1.rewardExp;
                loc2.messageInfo = StringHelper.getString(loc1.messageInfo);
                loc2.describe = StringHelper.getString(loc1.describe);
                loc2.awardItems = StringHelper.getString(loc1.awardItems);
                loc2.warfare = loc1.warfare;
                loc2.jumpCost = loc1.jumpCost;
                loc2.jumpLevel = loc1.jumpLevel;
                loc2.jumpBossNum = loc1.jumpBossNum;
                loc2.jumpTime = loc1.jumpTime;
                loc2.jumpCredit = loc1.jumpCredit;
                loc2.firstReward = StringHelper.getString(loc1.firstReward);
                this._FloorInfoDic[loc2.copyCode + "_" + loc2.realFloor] = loc2;
                if (this._maxFloorDic[loc2.copyCode]) 
                {
                    this._maxFloorDic[loc2.copyCode] = Math.max(this._maxFloorDic[loc2.copyCode], loc2.realFloor);
                    continue;
                }
                this._maxFloorDic[loc2.copyCode] = loc2.realFloor;
            }
            return;
        }

        public getMaxFloor(arg1: int): int
        {
            return this._maxFloorDic[arg1];
        }

        public getInfoByFloor(arg1: int): TMagicTowerConfig
        {
            if (Cache.instance.copy.copyInfo) 
            {
                return this._FloorInfoDic[Cache.instance.copy.copyInfo.code + "_" + arg1];
            }
            return null;
        }

        public getJumpFloorList(arg1: int): DataProvider
        {
            var loc1=null;
            var loc2=null;
            if (!this._jumpFloorListDic) 
            {
                this._jumpFloorListDic = new Map<any, any> /* flash.utils.Dictionary */();
                var loc3=0;
                var loc4=this._FloorInfoDic;
                for(loc2 of loc4) 
                {
                    if (!(loc2.jumpCost > 0)) 
                    {
                        continue;
                    }
                    if (!this._jumpFloorListDic[loc2.copyCode]) 
                    {
                        this._jumpFloorListDic[loc2.copyCode] = new DataProvider();
                    }
                    loc1 = new JumpFloorItemInfo();
                    loc1.info = loc2;
                    loc1.floor = this.getLastFloor(loc2.copyCode, loc2.floor);
                    (this._jumpFloorListDic[loc2.copyCode] as DataProvider).addItem(loc1);
                }
            }
            return this._jumpFloorListDic[arg1];
        }

        /* internal  */getLastFloor(arg1: int, arg2: int): int
        {
            var loc1=null;
            var loc2=0;
            var loc3=this._FloorInfoDic;
            for(loc1 of loc3) 
            {
                if (!(loc1.copyCode == arg1 && loc1.floor == (arg2 - 1))) 
                {
                    continue;
                }
                return loc1.realFloor;
            }
            return 0;
        }

        public isCopyCanJump(arg1: int): Boolean
        {
            var loc1=this.getJumpFloorList(arg1);
            if (loc1 && loc1.length > 0) 
            {
                return true;
            }
            return false;
        }

        public getJumpInfoByJumpFloor(arg1: int, arg2: int): TMagicTowerConfig
        {
            var loc2=null;
            var loc3=0;
            var loc1=this._jumpFloorListDic[arg1] as DataProvider;
            if (loc1) 
            {
                loc3 = 0;
                while (loc3 < loc1.length) 
                {
                    if ((loc2 = loc1.getItemAt(loc3) as JumpFloorItemInfo).floor == arg2) 
                    {
                        return loc2.info;
                    }
                    ++loc3;
                }
            }
            return null;
        }

        public static get instance(): MagicTowerConfig
        {
            if (MagicTowerConfig._instance == null) 
            {
                MagicTowerConfig._instance = new MagicTowerConfig();
            }
            return MagicTowerConfig._instance;
        }

        /* internal */ /* var */_FloorInfoDic: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_maxFloorDic: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_jumpFloorListDic: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: MagicTowerConfig;
    }
